import pygame
from modShape import Shape

class Rectangle(Shape):
    """长方形"""
    def __init__(self, color, x, y, width, height):
        Shape.__init__(self, color, x, y)
        self.width = width
        self.height = height
    
    def render(self, screen):
        color = self.what_is_your_color()
        rect = (self.x, self.y, self.width, self.height)
        pygame.draw.rect(screen, color, rect)

class Circle(Shape):
    """圆形"""
    def __init__(self, color, x, y, radius):
        Shape.__init__(self, color, x, y)
        self.radius = radius
    
    def render(self, screen):
        color = self.what_is_your_color()
        pygame.draw.circle(screen, color, (self.x, self.y), self.radius)

class SimplyShape:
    def __init__(self):
        pygame.init()
        pygame.display.set_caption("形状")
        self._screen = pygame.display.set_mode((800, 600))
        self._timer = pygame.time.Clock()

        self._listShapes = [
            Rectangle("crimson", 20, 30, 100, 50),
            Rectangle("lightblue", 150, 30, 100, 50),
            Circle("yellow", 50, 200, 30),
            Circle("darkgreen", 150, 200, 40)
        ]

    def run(self):
        keep_going = True
        while keep_going:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    keep_going = False
            
            self._screen.fill((0, 0, 0))
            
            # 渲染图形
            for shape in self._listShapes:
                shape.render(self._screen)
                shape.update()


            pygame.display.update()
            self._timer.tick(60)

        pygame.quit()

myShapes = SimplyShape()
myShapes.run()